Image processing apparatus and image processing method

ABSTRACT

The image processing apparatus inpaints a part of an image displayed on the display unit. The control unit determines a removal patch including a removal region and a first non-removal region that is a region that does not include the removal region in the image, and replace pixel values of pixels included in the removal region with pixel values of pixels outside the removal patch. The control unit calculates a distance from the removal region for pixels included in the first non-removal region, blends pixel values of the pixels included in at least a portion of the first non-removal region with the pixel values of the pixels outside the removal patch based on the calculated distance to obtain blended pixel values, and replaces the pixel values of the pixels included in the at least a portion of the first non-removal region with the blended pixel values.

PRIORITY

This application claims priority under 35 U.S.C. §119 to Japanese PatentApplications No. 2013-079231 filed on Apr. 5, 2013 and No 2014-50332filed on Mar. 13, 2014. The entire disclosure of Japanese PatentApplications No. 2013-079231 and No. 2014-50332 is hereby incorporatedherein by reference.

TECHNICAL FIELD

The present disclosure relates to an image processing technique forinpainting a portion of an image that is not as intended by a user.

BACKGROUND

There are cases where an image includes an unnecessary object, which isan object thought to be unnecessary by a user (such as facial blemishesor moles, or electric cables in the background). Conventionally, afunction for performing inpainting processing after removing such anunnecessary object from the image has been proposed. For example, animage processing method has been proposed in which inpainting isperformed by attaching the pixel values in a non-missing region to amissing region, which is a region from which an unnecessary object wasremoved. Specifically, patch sets including a missing patch, which is animage of a region that includes a missing region, and a reference patch,which is an image of a region that does not include a missing region,are provided, patch sets in which the missing patch and the referencepatch are comparatively similar are selected, and then a patch set inwhich the missing patch image and the reference patch image arecomparatively similar is selected based on the relationship betweenestimated pixel values in a missing region of the missing patch and thecorresponding pixel values of the reference patch. The missing patch isthen inpainted based on the reference patch in the patch set that wasselected (e.g., see WO 2011/061943).

SUMMARY

The present disclosure provides an image processing apparatus and animage processing method that are effective for obtaining a more naturalprocessing result in image inpainting processing for removing anunnecessary object from an image.

The image processing apparatus according to one aspect of the presentdisclosure is an image processing apparatus that inpaints a inpaintingtarget region in an image to be displayed. The image processingapparatus comprises: a display unit configured to display the imageconstituted by a predetermined number of pixels; and a control unitconfigured to control the display unit. The control unit is configuredto determine a removal patch including a removal region that is theinpainting target region and a first non-removal region that is a regionthat does not include the removal region in the image to be displayed onthe display unit, and replace pixel values of pixels included in theremoval region with pixel values of pixels outside the removal patch.The control unit is further configured to calculate a distance from theremoval region for pixels included in the first non-removal region,blend pixel values of the pixels included in at least a portion of thefirst non-removal region with the pixel values of the pixels outside theremoval patch based on the calculated distance to obtain blended pixelvalues, and replace the pixel values of the pixels included in the atleast a portion of the first non-removal region with the blended pixelvalues.

The image processing method according to another aspect of the presentdisclosure is an image processing method for inpainting a inpaintingtarget region in an image to be displayed on a display unit, the imageprocessing method including: determining a removal patch including aremoval region that is the inpainting target region and a non-removalregion that is a region that does not include the removal region in theimage to be displayed on the display unit; replacing pixel values ofpixels included in the removal region with pixel values of pixelsoutside the removal patch; calculating a distance from the removalregion for pixels included in the non-removal region; blending pixelvalues of the pixels included in at least a portion of the non-removalregion with the pixel values of the pixels outside the removal patchbased on the calculated distance to obtain blended pixel values; andreplacing the pixel values of the pixels included in the at least aportion of the non-removal region with the blended pixel values.

The image processing apparatus and the image processing method of thepresent disclosure are effective for obtaining a more natural processingresult in image inpainting processing for removing an unnecessary objectfrom an image.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a block diagram showing a schematic configuration of an imageprocessing apparatus.

FIG. 2 is a flowchart showing operations of the image processingapparatus.

FIG. 3 is a diagram showing an image resulting from reductionprocessing.

FIG. 4 is a flowchart showing operations in region designationprocessing.

FIG. 5 is a diagram for describing the state of a binary image generatedas a result of the region designation processing.

FIG. 6 is a flowchart showing operations in reduced image inpaintingprocessing.

FIG. 7 is a diagram for describing the relationship between a firstremoval patch and a reference patch in the reduced image inpaintingprocessing.

FIG. 8 is a diagram for describing the positions of removal/referencepatches recorded as a patch history.

FIG. 9 is a diagram showing the distance that the non-removal region isseparated from the removal region for each pixel in the reduced imageinpainting processing.

FIG. 10 is a diagram for describing a result of removal patchinpainting.

FIG. 11 is a diagram for describing the relationship between a secondremoval patch and a reference patch.

FIG. 12 is a diagram showing the distance that the non-removal region isseparated from the removal region for each pixel.

FIG. 13 is a diagram for describing a result of removal patchinpainting.

FIG. 14 is a diagram for describing a result of operations in thereduced image inpainting processing.

FIG. 15 is a flowchart showing operations in original image inpaintingprocessing.

FIG. 16 is a diagram for describing the relationship between a thirdremoval patch and a reference patch according to a variation.

FIG. 17 is a diagram showing the distance that the non-removal region isseparated from the removal region for each pixel according to thevariation.

DETAILED DESCRIPTION

Hereinafter, embodiments of the present disclosure will be described indetail with reference to the drawings as appropriate. Note that thereare cases where descriptions in greater detail than necessary will notbe given. For example, there are cases where detailed descriptions willnot be given for well-known matter, and where redundant descriptionswill not be given for configurations that are substantially the same.The purpose of this is to avoid unnecessary redundancy in the followingdescription and to facilitate understanding by a person skilled in theart. It will be apparent to those skilled in the art from thisdisclosure that the following descriptions of the embodiments areprovided for illustration only and not for the purpose of limiting theinvention as defined by the appended claims and their equivalents.

Note that the accompanying drawings and following description areprovided for sufficient understanding of the present disclosure by aperson skilled in the art, and are not intended to limit the subjectmatter recited in the claims.

Embodiment 1

Embodiment 1 will be described below with reference to FIGS. 1 to 17.

1. CONFIGURATION

FIG. 1 is a block diagram schematically showing the configuration of animage processing apparatus 1. The image processing apparatus 1 is anyelectronic device, such as a digital still camera, a digital videocamera, a personal computer, a mobile phone, or an information terminal.The image processing apparatus 1 includes a control unit 2 (example of acontrol unit) that performs overall control of operations of units inthe image processing apparatus 1; an image input unit 3, such as acamera or a scanner, that includes a lens and an imaging device andcaptures images; a storage unit 4 that records various types ofinformation such as captured images; a display unit 5 (example of adisplay unit), such as a liquid crystal monitor or an organic ELdisplay, that displays image information such as images; and anoperation input unit 6, such as a touch panel, that receives an input ofvarious types of operations from a user.

The control unit 2 includes a processor such as a CPU, and executesoperations of the image processing apparatus 1 by executing processingaccording to a predetermined program. The storage unit 4 may beconstituted by a hard disk, a silicon disk, an SD card (semiconductormemory), or the like. The storage unit 4 may be constituted by anelement that performs temporary storage, such as a cache or a RAM.

Also, the operation input unit 6 may be a pointing device such as amouse or a tablet, or may be a keyboard. Alternatively, the operationinput unit 6 may be an electronic pen of any of various systems, or thelike.

2. OPERATIONS

2-1. Operations of Image Processing Apparatus

Operations of the image processing apparatus 1 configured as describedabove will be described below with reference to the flowchart of FIG. 2.

In accordance with an instruction from a user, the control unit 2 of theimage processing apparatus 1 generates a reduced image from an imagecaptured by the image input unit 3. Alternatively, an image captured bythe image input unit 3 is stored in the storage unit 4 in advance, thatimage is read out from the storage unit 4, and the reduced image isgenerated. The generated reduced image is then displayed on the displayunit 5 (step S101).

Next, the control unit 2 recognizes an arbitrary region that wasdesignated by the user in the reduced image, for example, and generatesa binary image in which the pixels included in the designated regionmake up a removal region (step S102).

Next, the control unit 2 performs reduced image inpainting processing onthe removal region, as well as stores the procedure of the inpaintingprocessing (step S103).

Then control unit 2 then uses the stored inpainting processing procedureto perform inpainting processing on the image from before the reductionperformed in step S101 (original image) (step S104).

The following is a more detailed description of operations in thereduced image display processing (step S101), the region designationprocessing (step S102), the reduced image inpainting processing (stepS103), and the original image inpainting processing (step S104) shown inthe flowchart of FIG. 2.

2-2. Operations in Reduced Image Display Processing

FIG. 3 is a diagram showing a state in which a reduced image isdisplayed on a liquid crystal screen.

An image captured by the image input unit 3 or an image stored in thestorage unit 4 is constituted from 4,480 pixels horizontally and 3,360pixels vertically, for example. Each pixel has three pieces of digitaldata (referred to hereinafter as the “pixel value”) respectivelyindicating a luminance Y and color differences U and V. Note that sincethe image data format allows conversion between color spaces such as theRGB color space and the Lab color space, processing may be performedusing the results of conversion into another color space as the pixelvalue.

The number of pixels in the liquid crystal screen serving as the displayunit 5 is generally lower than with this type of image constituted froma large number of pixels (referred to hereinafter as the “originalimage”). The following description will take the example of a liquidcrystal screen constituted from 640 display pixels horizontally and 480display pixels vertically.

The control unit 2 generates a reduced image by reducing the originalimage to 1/K. The following description will take the example of K=7.First, the original image is evenly divided into square blocks made upof K×K (i.e., 7×7) pixels. This results in 640 blocks horizontally and480 blocks vertically. In view of this, it is sufficient to select thecenter pixel of each block, and use the pixel values of the centerpixels as the pixel value of the reduced image 10 (thinning processing).Alternatively, a configuration is possible in which average values arecalculated for the three luminance Y and color difference U and Vcomponents of the pixel values of the 49 pixels included in each block,and the resulting average values are used as the pixel values of thereduced image 10 (averaging processing).

FIG. 3 shows an example where the reduced image generated by the controlunit 2 in this way is displayed on the liquid crystal screen serving asthe display unit 5. The reduced image 10 obtained by reducing theoriginal image to 1/K includes a first subject 11, a second subject 12,a third subject 13, and the like. The following description will takethe example of the case where the first subject 11 among these threesubjects is set as the unnecessary object and removed, and theninpainting processing is performed on the removal region.

2-3. Operations in Region Designation Processing

FIG. 4 is a flowchart showing operations in region designationprocessing performed by the image processing apparatus 1. Also, FIG. 5is a diagram for describing a state in which a removal region designatedas an unnecessary object is generated as a binary image.

The control unit 2 of the image processing apparatus 1 displays thereduced image 10 on the liquid crystal screen serving as the displayunit 5 (FIG. 3), and then prompts the user to perform input. The usertouches the liquid crystal screen with their fingertip and traces theoutline portion of the first subject 11. The control unit 2 successivelyrecords the position of the fingertip detected by the touch panelserving as the operation input unit 6, and obtains a closed curve thatencloses the first subject 11. The interior of this closed curve is thendetermined to be an unnecessary object (step S201).

Note that the designation of the unnecessary object does not need to bedependent on user input as described above, and the unnecessary objectmay be detected automatically. For example, a configuration is possiblein which a line-shaped flaw such as debris or a scratch is automaticallydetected, and that flaw is automatically detected as the unnecessaryobject. Alternatively, it is also effective to use a procedure ofdividing the screen into several candidate regions (e.g., the firstsubject 11, the second subject 12, and the third subject 13) bydetermining differences in color, brightness, or the like. The user maybe allowed to select one or more regions from among the candidates.

After the unnecessary object has been recognized as described above, thecontrol unit 2 generates a binary image in which the pixels included inthe unnecessary object make up a removal region. Specifically, thebinary image is generated such that the values of the pixels inside theclosed curve that encloses the first subject 11 are 1 (true), and thevalues of the pixels outside the closed curve are 0 (false) (step S202).FIG. 5 shows an example of a binary image 21 generated in this way. Thenumber of pixels in the binary image is the same as the number of pixelsin the reduced image 10. In FIG. 5, the pixels that have the value of 1and are included in a removal region 22 are shown in gray, and thepixels that have the value of 0 and are included in a non-removal region23 are shown in white. The same follows the figures in the descriptionbelow.

2-4. Operations in Reduced Image Inpainting Processing

FIG. 6 is a flowchart showing operations in reduced image inpaintingprocessing performed by the image processing apparatus 1. FIGS. 7 to 13show operations in the reduced image inpainting processing.

The control unit 2 performs image inpainting processing on the reducedimage 10, specifically on the removal region 22 that underwent thebinary image processing (step S103 in FIG. 2). FIG. 7 is an enlargedview of the periphery of the removal region 22 of the binary imagesuperimposed on the reduced image 10 in FIG. 3 that is subjected toprocessing.

2-4-1. Processing in First Iteration

First, the control unit 2 determines a square removal patch 30 whosecenter is on an edge portion of the removal region 22 (the boundary ofthe region, which is a boundary line portion between the interior andexterior of the region) (step S301). As shown in FIG. 7, the removalpatch 30 is arranged so as to span the removal region 22 and thenon-removal region 23. The removal patch 30 has 16 pixels horizontallyand 16 pixels vertically, for example. These 256 pixels can be dividedinto the following two regions. Specifically, the first region is madeup of the pixels that are included in a removal region 30 a of theremoval patch 30, and the second region is made up of the pixels thatare included in a non-removal region 30 b. A boundary 30 c between thesetwo regions conforms to the edge portion of the removal region 22.

Next, the control unit 2 selects a reference patch 31 that correspondsto the removal patch 30 (step S302). The reference patch 31 is a squareregion made up of only pixels in the non-removal region 23, and has thesame number of pixels as the removal patch 30. Since the reduced image10 includes many candidates that satisfy this condition, the referencepatch is selected using the following procedure. Specifically, a degreeof similarity is obtained for the non-removal region 30 b of the removalpatch 30 and a corresponding partial region 31 b of each reference patch31. The reference patch 31 that has the highest degree of similarity isselected from among the candidates. Here, the degree of similarity iscalculated using a method such as the following. Specifically, the sumof squares is obtained for the difference between the pixel values ofthe pixels included in the non-removal region 30 b of the removal patch30 and the pixel values of the corresponding pixels included in thepartial region 31 b of each reference patch 31. It is sufficient thatthe smaller the sum of squares is, the higher the degree of similarityis determined to be.

As a result of the above procedure, one set of the removal patch 30 anda corresponding reference patch 31 is selected, and therefore thecontrol unit 2 records this result in the storage unit 4 as a patchhistory (step S303). It is sufficient that information such as thatshown in FIG. 8 is recorded with a history number 1. Specifically, thecentral position (Xc,Yc) of the removal patch 30, the center (Xs,Ys) ofthe reference patch 31, and the size P of the removal patch (e.g., 16pixels) are recorded.

Next, the control unit 2 calculates a distance D from the removal region30 a for each pixel included in the non-removal region 30 b of theremoval patch 30 (step S304). FIG. 9 shows the result of calculating thedistance D for all of the 16×16 pixels. In FIG. 9, the pixels includedin the removal region 30 a are marked with the distance D=0 (zero), andare shown in dark gray. On the other hand, the pixels included in thenon-removal region 30 b are marked with distance D numerical valuesindicating the shortest distance from the removal region 30 a obtainedas a city block distance (Manhattan distance).

Note that the present disclosure is not limited to using a city blockdistance in the method of calculating the shortest distance, and anormal distance (Euclidean distance) or the like may be used. Theprocessing speed can be increased when using a city block distance sinceonly integer arithmetic needs to be performed.

Also, when obtaining the shortest distance, it is sufficient to performcalculation using only the pixels included in the removal patch 30(16×16 pixels). The processing speed can be increased since there is noneed to calculate the distance for all of the pixels included in thereduced image 10 or the binary image 21 (640×480 pixels).

Next, the control unit 2 uses the following procedure to carry outinpainting processing on the removal patch 30 using the pixel values ofthe pixels in the reference patch 31 (step S305).

In the first process, the pixel values of the pixels in the removalregion 30 a of the removal patch 30 are replaced with the pixel valuesof the corresponding pixels in the partial region 31 a of the referencepatch 31. In FIG. 9, the portions shown in dark gray are pixels that aresubjected to this process.

In the second process, among the pixels in the non-removal region 30 bof the removal patch 30, the pixel values of the pixels for which thedistance D is less than a predetermined threshold value Dw (e.g., Dw=4pixels), that is to say D<Dw, are subjected to later-described blendprocessing that is performed using the pixel values of the correspondingpixels in the partial region 31 b of the reference patch 31. A region 30d shown in light gray in FIG. 9 is made up of the pixels that aresubjected to this process.

In the third process, among the pixels in the non-removal region 30 b ofthe removal patch 30, the current pixel values are saved for the pixelsfor which the distance D is greater than or equal to the threshold valueof Dw (i.e., D≧Dw). In other words, the pixels in a region 30 e shown inwhite in FIG. 9 are not subjected to any processing.

Next, the blend processing will be described. Letting Pc be the pixelvalue of a pixel in the removal patch 30, and Ps be the pixel value ofthe corresponding pixel in the reference patch 31, the second process isexecuted according to Equation 1 below. D indicates the distance of thispixel.

$\begin{matrix}{{{{when}\mspace{14mu} D} < {Dw}}{{Pc} = {{\frac{D}{Dw}{Pc}} + {\frac{{Dw} - D}{Dw}{Ps}}}}} & {{Equation}\mspace{14mu} 1}\end{matrix}$

Specifically, based on the distance D of the current pixel included inthe non-removal region 30 b of the removal patch 30, a blend ratio ofthe pixel value Pc of that pixel to the pixel value Ps of thecorresponding pixel in the reference patch 31 is determined to be D/Dwto (Dw−D)/Dw. The result of blending Pc and Ps based on the determinedblend ratio is then again substituted for the pixel value Pc. As can beseen from Equation 1, when distance D is D=0, then Pc−Ps, and thisrepresents the first process. Also, when D=Dw, then Pc=Pc and there isno change in the pixel value, and this represents the third process.Accordingly, while the distance D changes from D=0 to D=Dw, the blendratio of Pc to Ps changes according to the distance D. Accordingly,blended images in which the pixel value shifts from Pc to Ps areobtained between the first process and the third process.

FIG. 10 shows the result of performing the inpainting processing on theremoval patch 30 as described above. As a result of the first processdescribed above, the removal region 30 a of the removal patch 30 isreplaced with the corresponding partial region 31 a of the referencepatch 31. Accordingly, the inpainting processing is performed on aportion of the removal region 22. Furthermore, since the second processdescribed above is performed, the portion corresponding to the boundary30 c does not stand out unnaturally. In other words, even if there is aregion 30 e that does not change according to the third processdescribed above, there is a region 30 d that is a buffer region betweenthe removal region 30 a and the unchanging region 30 e, and thereforethe boundary 30 c does not stand out unnaturally, and a naturalprocessing result is obtained.

Note that the values of the distance D and the threshold value Dw needonly be numerical values that are less than or equal to half the size Sof the removal patch 30, that is to say satisfy the condition Dw<S/2.The higher the value of Dw is, the less likely the boundary is to standout, but there is also a tendency for the calculation time to be longerand for the image to be more likely to look blurred.

Next, the control unit 2 updates the removal region 22 (step S306).Specifically, the binary image 21 that was generated in step S202 inFIG. 4 is updated. The pixels in the region of the removal region 22that corresponds to the removal patch 30 are changed to the non-removalregion 23 by changing their pixel values to 0. This processing isnecessary for properly carrying out later-described step S307. Thisprocessing is also necessary for correctly calculating the distance D(step S304) in the second and successive iterations.

Next, the control unit 2 determines whether or not a removal region 22remains (step S307). This determination may be performed by searchingall of the pixels in the binary image 21 for a pixel having the valueof 1. If even one pixel has the value of 1, a removal region 22 remains,and therefore the procedure returns to step S301, and processing isperformed a second time.

2-4-2. Processing in Second Iteration

Similarly to the first iteration, the control unit 2 performs theprocessing of steps S301 to S306 shown in the flowchart of FIG. 6.Specifically, a square removal patch 32 whose center is on the edgeportion of the removal region 22 is determined as shown in FIG. 11 (stepS301). The removal patch 32 is constituted from the pixels that areincluded in a removal region 32 a and the pixels that are included in anon-removal region 32 b. Boundaries 32 c and 32 f between these tworegions conform to the edge portion of the removal region 22. Here, theboundary 32 f is a new boundary that appeared as a result of theprocessing in the first iteration. Specifically, it is a new boundarygenerated as a result of replacing the removal region 30 a of theremoval patch 30 with the corresponding partial region 31 a of thereference patch 31.

Next, the control unit 2 selects a reference patch 33 that correspondsto the removal patch 32 (step S302). As described above, the referencepatch 33 is selected based on the degree of similarity between thenon-removal region 32 b of the removal patch 32 and a correspondingpartial region 33 b of the reference patch 33.

Next, the control unit 2 records the removal patch 32 and the result ofselecting the corresponding reference patch 33 with a history number 2in the patch history (step S303).

Next, the control unit 2 calculates a distance D from the removal region32 a for each pixel included in the non-removal region 32 b of theremoval patch 32 (step S304). FIG. 12 shows the result of calculatingthe distance D for all of the 16×16 pixels. Since the removal region 22is updated in step S306 in the first iteration, it is possible tocalculate a distance D that also corresponds to the new boundary 32 fthat was generated in the first iteration.

Next, the control unit 2 uses the following procedure to carry outinpainting processing on the removal patch 32 using the pixel values ofthe pixels in the reference patch 33 (step S305).

In the first process, the pixel values of the pixels in the removalregion 32 a of the removal patch 32 are replaced with the pixel valuesof the corresponding pixels in the partial region 33 a of the referencepatch 33.

In the second process, among the pixels in the non-removal region 32 bof the removal patch 32, the pixels for which the distance D is lessthan the predetermined threshold value Dw, that is to say D<Dw (thepixels in a region 32 d in FIG. 12), are subjected to the blendprocessing in accordance with the calculation formula shown inEquation 1. Specifically, based on the distance D of the current pixelincluded in the non-removal region 32 b of the removal patch 32, theblend ratio of the pixel value Pc of that pixel to the pixel value Ps ofthe corresponding pixel in the partial region 33 b of the referencepatch 31 is determined to be D/Dw to (Dw−D)/Dw. The result of blendingPc and Ps based on the determined blend ratio is then again substitutedfor the pixel value Pc.

In the third process, among the pixels in the non-removal region 32 b ofthe removal patch 32, the current pixel values are saved for the pixelsfor which the distance D is greater than or equal to the threshold valueof Dw. In other words, the pixels in a region 32 e in FIG. 12 are notsubjected to any processing.

FIG. 13 shows the result of performing the inpainting processing on theremoval patch 32 as described above. As a result of the first processdescribed above, the removal region 32 a of the removal patch 32 isreplaced with the corresponding partial region 33 a of the referencepatch 33. Accordingly, the inpainting processing is performed on aportion of the removal region 22. Furthermore, since the second processdescribed above is performed, the portion corresponding to theboundaries 32 c and 32 f does not stand out unnaturally. In other words,even if there is a region 32 e that does not change according to thethird process described above, there is a region 32 d that is a bufferregion between the removal region 32 a and the unchanging region 32 e,and therefore the boundaries 32 c and 32 f do not stand out unnaturally,and a natural processing result is obtained.

The boundary 32 c shown in FIG. 11 is a boundary that already existed atthe stage of the region designation processing in step S102 of FIG. 2.In contrast, the boundary 32 f is a new boundary that was generated inthe processing in the first iteration. However, in the image processingmethod of the present embodiment, the removal region 22 is alwaysupdated in step S305, and therefore the new boundary 32 f that wasgenerated does not stand out either, and a natural processing result isobtained.

Next, the control unit 2 updates the removal region 22 (step S306). Inthe binary image 21, the pixels in the region of the removal region 22that corresponds to the removal patch 32 are changed to the non-removalregion 23 by changing their pixel values to 0.

Next, the control unit 2 determines whether or not a removal region 22remains (step S307). Steps S301 to S306 are then repeatedly executeduntil no removal region 22 remains. As a result, steps S301 to S306 arerepeated N times. As shown in FIG. 14, a natural inpainting processingresult in which the first subject 11 has been removed from the reducedimage 10 is obtained.

As described above, with the image processing method of the presentembodiment, the distance D from the removal region 22 is calculated foreach pixel in the non-removal region 23 in the removal patch (stepS304). The pixel values of the pixels in the removal region 22 of theremoval patch are then replaced with the pixel values of thecorresponding pixels in the reference patch (step S305), and among thepixels in the non-removal region 23 of the removal patch, pixels forwhich the distance D is less than the predetermined threshold value Dw(i.e., D<Dw) are subjected to the blend processing so as to be blendedin accordance with the calculation formula shown in Equation 1 (stepS305). As a result, the boundary between the removal region 22 and thenon-removal region 23 in the removal patch does not stand outunnaturally, and a natural processing result is obtained.

Also, each time the pixel values of the pixels in the removal region 22of the removal patch are replaced with the pixel values of thecorresponding pixels in the reference patch, the removal region 22 isupdated (step S306). As a result, new boundaries that are generated aresult of the pixel value replacement (boundaries between the removalregion 22 and the non-removal region 23) also do not stand outunnaturally, and a natural processing result is obtained.

2-5. Operations in Original Image Inpainting Processing

After performing the image inpainting processing (step S103 in FIG. 2)on the reduced image 10, the control unit 2 of the image processingapparatus 1 performs original image inpainting processing (step S104).FIG. 15 is a flowchart showing operations in inpainting processingperformed on the original image

First, the control unit 2 generates a binary image that has the samenumber of pixels as the original image by enlarging the binary image 21that corresponds to the reduced image 10 to a factor of K (step S401).The enlargement factor K here is the inverse of the reduction factor 1/Kin step S101 in FIG. 2. For example, if an image enlarged to a factor of7 vertically and horizontally is generated from a binary image having640 pixels vertically×480 pixels horizontally, a binary image having4,480×3,360 pixels will be obtained. Note that the binary image 21 thatis subjected to the enlargement processing is the binary image that wasgenerated in step S202 in FIG. 4. In other words, the binary image thatis subjected to the enlargement processing is the binary image 21 thatincludes the removal region 22 as shown in FIG. 5. The objective of stepS401 is to enlarge the position and size of the removal region 22 to afactor of K.

Next, the control unit 2 performs the processing of loop A on all of thepatch histories (step S402) that were recorded in the reduced imageinpainting processing (step S103 in FIG. 2). The processing of loop A isexecuted the same number of times as the repetition number N (therepetition number N from steps S301 to S306 in FIG. 6) in the reducedimage inpainting processing (step S103 in FIG. 2). The patch historiesare reproduced in the order that they were recorded in the reduced imageinpainting processing (step S103 in FIG. 2). The processing of stepsS403, S404, S405, and S406 in FIG. 15 is then executed using the patchhistory that was recorded in step S303 in FIG. 6.

First, the control unit 2 calculates the positions and sizes of theremoval patch and the reference patch with respect to the original image(step S403). The enlargement factor K of the reduced image 10 and theoriginal image is used to perform the calculation shown below.Specifically, the central position of the removal patch 30 is calculatedaccording to (K×Xc,K×Yc), the central position of the reference patch 31is calculated according to (K×Xs,K×Ys), and the size of the removalpatch is calculated according to K×P (e.g., 7×16=112 pixels).

Next, the control unit 2 calculates the distance D from the removalregion for each pixel included in the non-removal region of the removalpatch (step S404). For example, in the case of a removal patch made upof 112×112 pixels, the shortest distance D from the removal regioncalculated in step S401 is calculated as a city block distance.

Next, the control unit 2 uses the following procedure to carry outinpainting processing on the removal patch using the pixel values of thepixels in the reference patch (step S405).

In the first process, the pixel values of the pixels in the removalregion of the removal patch are replaced with the pixel values of thecorresponding pixels of the reference patch.

In the second process, among the pixels in the non-removal region of theremoval patch, the pixel values of the pixels for which the distance Dis less than the predetermined threshold value Dw (e.g., Dw=4 pixels)multiplied by a factor of M (i.e., D<M×Dw) are subjected to blendprocessing similar to that in Equation 1 using the pixel values of thecorresponding pixels of the reference patch.

In the third process, among the pixels in the non-removal region of theremoval patch, the current pixel values are saved for the pixels forwhich the distance D is greater than or equal to M×Dw (i.e., D≧M×Dw). Inother words, the pixels in the region 30 e shown in white in FIG. 9 arenot subjected to any processing.

Next, the blend processing in step S405 will be described. Letting Pc bethe pixel value of a pixel in the removal patch, and Ps be the pixelvalue of the corresponding pixel in the reference patch, the secondprocess is executed according to Equation 2 below. D indicates thedistance of this pixel.

$\begin{matrix}{{{{when}\mspace{14mu} D} < {M \times {Dw}}}{{Pc} = {{\frac{D}{M \times {Dw}}{Pc}} + {\frac{{M \times {Dw}} - D}{M \times {Dw}}{Ps}}}}} & {{Equation}\mspace{14mu} 2}\end{matrix}$

Specifically, based on the distance D of the current pixel included inthe non-removal region of the removal patch, the blend ratio of thepixel value Pc of that pixel to the pixel value Ps of the correspondingpixel in the reference patch is determined to be D/(M×Dw) to(mxDw−D)/M×Dw. The result of blending Pc and Ps based on the determinedblend ratio is then again substituted for the pixel value Pc.

Here, an enlargement factor M for the threshold value may be the same asthe enlargement factor K of the reduced image 10 and the original image,that is to say M=K (e.g., M=7). Alternatively, M may be a numericalvalue smaller than K (e.g., M=4). The processing speed can be increasedin this case.

Next, the control unit 2 updates the removal region (step S406). In theremoval region that was calculated in step S401, the pixels in theregion that corresponds to the removal patch are changed to thenon-removal region by changing their pixel values to 0.

As described above, when the processing of steps S403, S404, S405, and5406 has been carried out on all of the patch histories (step S402) thatwere recorded in the reduced image inpainting processing (step S103),original image inpainting processing is complete.

As described above, in the image processing method of the presentembodiment, original image inpainting processing is completed by merelycarrying out the processing of step S402 on all of the patch historiesthat were recorded in the reduced image inpainting processing (step S103in FIG. 2). Accordingly, there is no need to again select a referencepatch that corresponds to the removal patch. In other words, there is noneed for processing that corresponds to step S302 in FIG. 6, thus makingit possible to increase the processing speed.

Note that the degree of similarity is calculated for the removal patchand the reference patch in step 302. The effort for calculating thisdegree of similarity is proportional to the number of pixels. Also, thenumber of reference patches that are candidates is also proportional tothe number of pixels. Accordingly, the calculation effort required toselect a reference patch is proportional to the square of the number ofpixels. Assume that processing corresponding to step S302 has beencarried out on an original image. With an original image that is afactor of K (e.g., a factor of 7) of the reduced image 10, the number ofpixels increases to the square of K (a factor of 49). Accordingly, acalculation effort corresponding to the fourth power of K (a factor of2,401) is required to select a corresponding reference patch based onthe removal patch enlarged to a factor of K.

Also, in the image processing method of the present embodiment, thedistance D from the removal region is calculated for each pixel in thenon-removal region of the removal patch (step S404). Then, the pixelvalues of the pixels in the removal region of the removal patch arereplaced with the pixel values of the corresponding pixels of thereference patch (step S405), and among the pixels in the non-removalregion of the removal patch, the pixel values of the pixels for whichthe distance D is less than M×Dw (i.e., D<M×Dw), are subjected to theblend processing so as to be blended in accordance with the calculationformula shown in Equation 2 (step S405). As a result, in the originalimage as well, the boundary between the removal region and thenon-removal region in the removal patch does not stand out unnaturally,and a natural processing result is obtained.

3. VARIATIONS

The processing of step S304 and step S305 in FIG. 6 described in theabove embodiment, or the processing in step S404 and step S405 in FIG.15 can be replaced with a processing method such as that describedbelow. The following description takes the example of the reduced imageinpainting processing of step S103 in FIG. 2. FIGS. 16 and 17 arediagrams for describing operations in this variation.

After the above-described processing in the second iteration, thedetermination result in step S307 is that a removal region 22 remains,and therefore the procedure returns to step S301, and processing isperformed a third time. Similarly to the first and second iterations,the control unit 2 performs the processing of steps S301 to S306 shownin the flowchart of FIG. 6.

First, the control unit 2 determines a square removal patch 34 whosecenter is on an edge portion of the removal region 22 as shown in FIG.16 (step S301). The removal patch 34 is constituted from the pixels thatare included in a removal region 34 a and the pixels that are includedin a non-removal region 34 b. Boundaries 34 c and 34 f between these tworegions conform to the edge portion of the removal region 22.

Next, the control unit 2 selects a reference patch 35 that correspondsto the removal patch 34 (step S302). The removal patch 34 and the resultof selecting the corresponding reference patch 35 are then recorded witha history number 3 in the patch history (step S303).

Next, the control unit 2 calculates a distance D from the removal region34 a for each pixel included in the non-removal region 34 b of theremoval patch 34 (step S304). Here, focus is placed on the positions ofthe boundaries 34 c and 34 f, and the region for calculating thedistance D is expanded.

Specifically, if the boundary between the removal region 22 and thenon-removal region 23 is in the vicinity of an end portion of theremoval patch, the distance from the removal region 22 is calculated forthe pixels in the periphery of the removal patch as well. Here, thedetermination of whether or not the boundary is in the vicinity of anend portion of the removal patch is made by measuring the distance inthe direction orthogonal to the boundary.

In the example of FIG. 16, the boundary 34 f is in the vicinity of aleft end portion 34 g of the removal patch 34. In view of this, anexpanded region 34 h made up of pixels on the left side of the removalpatch 34 is added. Here, the width of the expanded region 34 h is Dw−1pixels (e.g., 3 pixels) relative to the threshold value Dw. FIG. 17shows the results of calculating the distance D for 19 pixelshorizontally due to the addition of the expanded region 34 h, and 16pixels vertically. It can be seen that among the pixels included in theremoval patch 34, the distance D for a left end pixel 34 i is D=1, whichis less than Dw−1. However, the distance D for the pixel on the left endof the expanded region 34 h is D=4, which is the same as the thresholdvalue Dw.

Next, the control unit 2 uses the following procedure to carry outinpainting processing on the removal patch 34 using the pixel values ofthe pixels in the reference patch 35 (step S305).

In the first process, the pixel values of the pixels in the removalregion 34 a of the removal patch 34 are replaced with the pixel valuesof the corresponding pixels in the partial region 35 a of the referencepatch 35.

In the second process, among the pixels in the non-removal region 34 bof the removal patch 34, the pixels for which the distance D is lessthan the predetermined threshold value Dw, that is to say D<Dw (thepixels in a region 34 d in FIG. 17), are subjected to the blendprocessing in accordance with the calculation formula shown in Equation1.

Furthermore, among the pixels in the expanded region 34 h as well, thepixels for which the distance D is less than the predetermined thresholdvalue Dw (i.e., D<Dw) are subjected to the blend processing inaccordance with the calculation formula shown in Equation 1. Here, anexpanded region 35 h in the periphery (on the left side) of thereference patch 35 is provided in correspondence with the expandedregion 34 h provided in the periphery (on the left side) of the removalpatch 34.

Specifically, based on the distance D of the current pixel included inthe expanded region 34 h, the blend ratio of the pixel value Pc of thatpixel to the pixel value Ps of the corresponding pixel in the expandedregion 35 h is determined to be D/Dw to (Dw−D)/Dw. The result ofblending Pc and Ps based on the determined blend ratio is then againsubstituted for the pixel value Pc.

In the third process, among the pixels in the non-removal region 34 b ofthe removal patch 34, the current pixel values are saved for the pixelsfor which the distance D is greater than or equal to the threshold valueof Dw. In other words, the pixels in a region 34 e in FIG. 17 are notsubjected to any processing.

In the expanded region 34 h as well, the current pixel values are savedfor the pixels for which the distance D is greater than or equal to thethreshold value of Dw.

The control unit 2 performs inpainting processing on the removal patch34 as described above. As a result of the first process described above,the removal region 34 a of the removal patch 34 is replaced with thecorresponding partial region 35 a of the reference patch 35.Accordingly, the inpainting processing is performed on a portion of theremoval region 22. Furthermore, since the second process described aboveis performed, the portion corresponding to the boundaries 34 c and 34 fdoes not stand out unnaturally, and a natural processing is obtained.

4. CONCLUSION

As described above, according to the image processing apparatus 1 of theabove embodiment, the control unit 2 determines a removal patch thatincludes pixels in a removal region and pixels in a non-removal region(step S301 in FIG. 6), selects a reference patch that includes pixels ina non-removal region and corresponds to the removal patch (step S302 inFIG. 6), obtains the distance from the removal region for the pixelsincluded in the non-removal region of the removal patch (step S304 inFIG. 6), and replaces the pixel values of the pixels in the removalregion of the removal patch with the pixel values of the correspondingpixels of the reference patch (step S305 in FIG. 6). The control unit 2sets the pixel values in the vicinity of the boundary between theremoval region and the non-removal region in the removal patch to theresult of blending the pixel values of pixels in the non-removal regionof the removal patch with the pixel values of corresponding pixels ofthe reference patch based on the distances (step S305 in FIG. 6).Accordingly, in the image inpainting processing for removing anunnecessary object, the boundary between the removal region and thenon-removal region does not standout, and a natural processing result isobtained.

Furthermore, according to the image processing apparatus 1 of thevariation of the above embodiment, the control unit 2 obtains thedistance from the removal region for pixels in the periphery of an endportion of the removal patch included in the non-removal region of theremoval patch (step S304 in FIG. 6), and sets the pixel values of pixelsin the periphery of the end portion of the removal patch to the resultof blending the pixel values of the pixels in the periphery of the endportion of the removal patch with the pixel values of the correspondingpixels in the periphery of the end portion of the reference patch basedon the distances (step S305 in FIG. 6). Accordingly, in the imageinpainting processing for removing an unnecessary object, the boundarybetween the removal region and the non-removal region does not standout, and a natural processing result is obtained.

Other Embodiments

Some or all of the processing in the above-described embodiments may berealized by computer programs. Also, some or all of the processingexecuted by the image processing apparatus 1 is executed by a processorsuch as a central processing unit (CPU) in a computer. Also, programsfor executing the processing are stored in a storage device such as ahard disk or a ROM, and are executed in the ROM or read out to a RAM andthen executed.

Also, the processing executed by the image processing apparatus 1 may berealized by hardware, or may be realized by software (including the caseof being realized together with an OS (operating system), middleware, ora predetermined library). Furthermore, such processing may be realizedby a combination of software and hardware.

The image processing apparatus 1 of the above-described embodiments maybe realized as an image processing method or a computer program forcausing a computer to execute image processing. Also, acomputer-readable recording medium recording the program is encompassedin the present invention. Here, examples of the computer-readablerecording medium include a flexible disk, a hard disk, a CD-ROM, an MO,a DVD, a DVD-ROM, a DVD-RAM, a BD (Blu-ray Disc), and a semiconductormemory.

The computer program is not limited to being recorded on the recordingmedium, and may be transmitted via, for example, an electricalcommunication line, a wireless or wired communication line, or a networktypified by the Internet.

Also, the execution sequence of the image processing in theabove-described embodiments is not necessarily limited to thedescription of the above embodiments, and the steps in the executionsequence can be interchanged without departing from the gist of theinvention.

Embodiments have been described above as illustrative examples oftechniques of the present invention. The accompanying drawings anddetailed description have been provided for this purpose.

Accordingly, the constituent elements included in the accompanyingdrawings and the detailed description may include not only constituentelements that are essential to solving the problem, but also constituentelements that are not essential to solving the problem, in order toillustrate examples of the techniques. For this reason, thesenon-essential constituent elements should not be immediately found to beessential constituent elements based on the fact that they are includedin the accompanying drawings or detailed description.

Also, the above-described embodiments are for illustrating examples ofthe techniques of the present invention, and therefore variousmodifications, substitutions, additions, omissions, and the like can bemade within the scope of the claims or a scope equivalent thereto.

The present invention is applicable to electronic devices such asdigital cameras, digital video cameras, personal computers, mobilephones, and information terminals.

GENERAL INTERPRETATION OF TERMS

In understanding the scope of the present disclosure, the term“comprising” and its derivatives, as used herein, are intended to beopen ended terms that specify the presence of the stated features,elements, components, groups, integers, and/or steps, but do not excludethe presence of other unstated features, elements, components, groups,integers and/or steps. The foregoing also applies to words havingsimilar meanings such as the terms, “including”, “having” and theirderivatives. Also, the terms “part,” “section,” “portion,” “member” or“element” when used in the singular can have the dual meaning of asingle part or a plurality of parts. Also as used herein to describe theabove embodiment(s), the following directional terms “forward”,“rearward”, “above”, “downward”, “vertical”, “horizontal”, “below” and“transverse” as well as any other similar directional terms refer tothose directions of the image processing apparatus and image processingmethod. Accordingly, these terms, as utilized to describe the technologydisclosed herein should be interpreted relative to the image processingapparatus and image processing method.

The term “configured” as used herein to describe a component, section,or part of a device includes hardware and/or software that isconstructed and/or programmed to carry out the desired function.

The terms of degree such as “substantially”, “about” and “approximately”as used herein mean a reasonable amount of deviation of the modifiedterm such that the end result is not significantly changed.

While only selected embodiments have been chosen to illustrate thepresent invention, it will be apparent to those skilled in the art fromthis disclosure that various changes and modifications can be madeherein without departing from the scope of the invention as defined inthe appended claims. For example, the size, shape, location ororientation of the various components can be changed as needed and/ordesired. Components that are shown directly connected or contacting eachother can have intermediate structures disposed between them. Thefunctions of one element can be performed by two, and vice versa. Thestructures and functions of one embodiment can be adopted in anotherembodiment. It is not necessary for all advantages to be present in aparticular embodiment at the same time. Every feature which is uniquefrom the prior art, alone or in combination with other features, alsoshould be considered a separate description of further inventions by theapplicants, including the structural and/or functional concepts embodiedby such feature(s). Thus, the foregoing descriptions of the embodimentsaccording to the present invention are provided for illustration only,and not for the purpose of limiting the invention as defined by theappended claims and their equivalents.

What is claimed:
 1. An image processing apparatus that inpaints ainpainting target region in an image to be displayed, the imageprocessing apparatus comprises: a display unit configured to display theimage constituted by a predetermined number of pixels; and a controlunit configured to control the display unit, the control unit beingconfigured to: determine a removal patch including a removal region thatis the inpainting target region and a first non-removal region that is aregion that does not include the removal region in the image to bedisplayed on the display unit; replace pixel values of pixels includedin the removal region with pixel values of pixels outside the removalpatch; calculate a distance from the removal region for pixels includedin the first non-removal region; blend pixel values of the pixelsincluded in at least a portion of the first non-removal region with thepixel values of the pixels outside the removal patch based on thecalculated distance to obtain blended pixel values; and replace thepixel values of the pixels included in the at least a portion of thefirst non-removal region with the blended pixel values.
 2. The imageprocessing apparatus according to claim 1, wherein the control unit isfurther configured to: (i) determine a reference patch corresponding tothe removal patch, the reference patch being constituted by a secondnon-removal region that is different from the first non-removal regionand includes pixels corresponding to the pixels of the removal patch;(ii) replace the removal region with a non-removal region by replacingthe pixel values of the pixels included in the removal region with pixelvalues of corresponding pixels in the second non-removal region of thereference patch; and (iii) blend the pixel values of the pixels includedin the at least a portion of the first non-removal region with pixelvalues of corresponding pixels in the second non-removal region of thereference patch based on the calculated distance to obtain the blendedpixel values; and (iv) replace the pixel values of the pixels includedin the at least a portion of the first non-removal region with theblended pixel values.
 3. The image processing apparatus according toclaim 2, wherein the control unit is further configured to repeat theprocesses (i) to (iv) until all removal regions are excluded from theimage:
 4. The image processing apparatus according to claim 2, whereinthe control unit is further configured to: calculate a distance from theremoval region for pixels in the vicinity of and outside of a peripheryof the removal patch; blend pixel values of the pixels in the vicinityof and outside of the periphery of the removal patch with pixel valuesof corresponding pixels in the vicinity of and outside of a periphery ofthe reference patch based on the calculated distance to obtain blendedpixel values; and replace the pixel values of the pixels included in thevicinity of and outside of the periphery of the removal patch with theblended pixel values.
 5. The image processing apparatus according toclaim 2, wherein the control unit is further configured to display areduced image as the image, the reduced image being obtained by reducingan original image to 1/K.
 6. The image processing apparatus according toclaim 5, wherein the control unit is further configured to: store ahistory information including at least a size of the removal patch, aposition of the removal patch, and a position of the reference patch;and perform inpainting on a target region of the original image based onthe stored history information, the original image being obtained byenlarging the reduced image K times.
 7. The image processing apparatusaccording to claim 6, wherein the control unit is further configured toperform the same number of inpainting processes on the target region ofthe original image as on the reduced image.
 8. The image processingapparatus according to claim 1, wherein the control unit is furtherconfigured to: replace pixel values of the pixels included in the firstnon-removal region with the blended pixel values when the calculateddistance is less than a predetermined value; and leave the pixel valuesof the pixels included in the first non-removal region when thecalculated distance is equal to or greater than the predetermined value.9. The image processing apparatus according to claim 2, wherein thecontrol unit is further configured to determine the reference patchbased on similarity between pixel values of the pixels included in thefirst non-removal region and pixel values of pixels included in thereference patch.
 10. The image processing apparatus according to claim2, wherein the reference patch includes the same number of pixels as theremoval patch.
 11. An image processing method for inpainting ainpainting target region in an image to be displayed on a display unit,the image processing method including: determining a removal patchincluding a removal region that is the inpainting target region and anon-removal region that is a region that does not include the removalregion in the image to be displayed on the display unit; replacing pixelvalues of pixels included in the removal region with pixel values ofpixels outside the removal patch; calculating a distance from theremoval region for pixels included in the non-removal region; blendingpixel values of the pixels included in at least a portion of thenon-removal region with the pixel values of the pixels outside theremoval patch based on the calculated distance to obtain blended pixelvalues; and replacing the pixel values of the pixels included in the atleast a portion of the non-removal region with the blended pixel values.